﻿@model ConferenceTrafficModel
@{
	ViewBag.Title = Resources.ConferenceTraffic + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.TrafficName：<input id="selTrafficName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceTraffic, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-add" onclick="addData();" plain="true">@Resources.Create</a>
		}
	</div>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceTraffic" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Create</h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
					<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
						<tr>
							<td style="text-align: right;" class="w1 c1">@Resources.ConferenceName：</td>
							<td style="text-align: left;" class="w2 c2">
								<input id="hidID" name="Id" type="hidden" />
								<input id="hidConferenceId" name="ConferenceId" type="hidden" />
								<input id="txtConferenceName" disabled class="easyui-textbox" style="height:27px; width:300px;" value="@ViewBag.ConferenceName">
							</td>
							<td style="text-align: right;" class="w1 c1"></td>
							<td style="text-align: left;" class="w2 c2"></td>
						</tr>
						<tr>
							<td style="text-align: right;" class="w1 c3">@Resources.TrafficName：</td>
							<td style="text-align: left;" class="w2 c4">
								<input id="txtTrafficName" name="TrafficName" class="easyui-textbox" style="height:27px; width:300px;" data-options="required:true,validType:['length[1,100]']" />
							</td>
							<td style="text-align: right;" class="w1 c3">@Resources.TrafficType：</td>
							<td style="text-align: left;" class="w2 c4">
								<select id="ddlTrafficType" name="TrafficType" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
									<option value="@ConstValues.TrafficType.接机">@Resources.ArrivalService</option>
									<option value="@ConstValues.TrafficType.送机">@Resources.DeparturalService</option>
									<option value="@ConstValues.TrafficType.接送机">@Resources.ArrivalDeparturalService</option>
								</select>
							</td>
						</tr>
						<tr>
							<td style="text-align: right;" class="w1 c1">@Resources.Fee：</td>
							<td style="text-align: left;" class="w2 c2">
								<input id="txtPrice" name="Price" class="easyui-numberbox" style="height:27px; width:300px;" data-options="required:true,precision:2">
							</td>
							<td style="text-align: right;" class="w1 c1">@Resources.Currency：</td>
							<td style="text-align: left;" class="w2 c2">
								<select id="ddlCurrency" name="Currency" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
									<option value="@ConstValues.Currency.人民币">@Resources.RMB</option>
									<option value="@ConstValues.Currency.美元">@Resources.Dollar</option>
								</select>
							</td>
						</tr>
						<tr>
							<td style="text-align: right;" class="w1 c3">@Resources.Status：</td>
							<td style="text-align: left;" class="w2 c4">
								<select id="ddlStatus" name="Status" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'">
									<option value="@ConstValues.Status.正常">@Resources.Normal</option>
									<option value="@ConstValues.Status.暂停">@Resources.Pause</option>
								</select>
							</td>
							<td style="text-align: right;" class="w1 c3">@Resources.Sort：</td>
							<td style="text-align: left;" class="w2 c4">
								<input id="txtSort" name="Sort" class="easyui-numberbox" style="height:27px; width:300px;" />
							</td>
						</tr>
						<tr>
							<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
							<td style="text-align: left;" class="w2 c2" colspan="3">
								<input id="txtRemark" name="Remark" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
							</td>
						</tr>
					</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceTraffic");
	common.setCurrentParentMenu("#menu_a4");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#selTrafficName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceTrafficController.GetData),
					nameof(ConferenceTrafficController).GetControllerName(),
					new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			remoteSort:true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceTraffic, RoleType.修改) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceTraffic, RoleType.删除))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 200,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.trafficName == null ? "" : rec.trafficName.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceTraffic, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceTraffic, RoleType.删除))
							{
								<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
									+ rec.id + "\",\"" + tmp + "\")'>@Resources.Delete</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "trafficName", title: "@Resources.TrafficName", align: "center", sortable: true, width: 200 },
				{ field: "trafficType", title: "@Resources.TrafficType", align: "center", sortable: true, width: 200 },
				{ field: "price", title: "@Resources.Fee", align: "center", sortable: true, width: 150 },
				{ field: "currency", title: "@Resources.Currency", align: "center", sortable: true, width: 100 },
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.正常") {
							return "@Resources.Normal"
						} else {
							return "@Resources.Pause"
						}
					}
				},
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 100 },
				{ field: "createIP", title: "@Resources.CreateIP", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelTrafficName: $("#selTrafficName").textbox("getValue")
		});
	}

	function addData() {
		$("#hdnWindowType").val("add");
		$("#detailWindowTitle").text("@Resources.Create");
		$("#hidID").val("");
		$("#txtTrafficName").textbox("setValue", "");
		$("#ddlTrafficType").combobox("setValue", "");
		$("#txtPrice").numberbox("setValue","");
		$("#ddlCurrency").combobox("setValue","");
		$("#ddlStatus").combobox("setValue", "@ConstValues.Status.正常");
		$("#txtSort").numberbox("setValue", @ConstValues.DefaultSort);
		$("#txtRemark").textbox("setValue", "");
		$("#detailWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceTrafficController.GetEditData),
				nameof(ConferenceTrafficController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hdnWindowType").val("edit");
				$("#detailWindowTitle").text("@Resources.Modify");
				$("#hidID").val(id);
				$("#txtTrafficName").textbox("setValue", data.data.trafficName);
				$("#ddlTrafficType").combobox("setValue", data.data.trafficType);
				$("#txtPrice").numberbox("setValue",data.data.price);
				$("#ddlCurrency").combobox("setValue",data.data.currency);
				$("#ddlStatus").combobox("setValue", data.data.status);
				$("#txtSort").numberbox("setValue", data.data.sort);
				$("#txtRemark").textbox("setValue", data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function deleteData(id, name) {
		var confirmMessage = "@Resources.CfmDelete";
		confirmMessage = confirmMessage.replace(/\{0\}/g, name);
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#hidID").val(id);
				$.post("@Url.Action(nameof(ConferenceTrafficController.Delete),
						nameof(ConferenceTrafficController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});
					switch ($("#hdnWindowType").val())
					{
						case "add":
							$.post("@Url.Action(nameof(ConferenceTrafficController.Create),
									nameof(ConferenceTrafficController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
						case "edit":
							$.post("@Url.Action(nameof(ConferenceTrafficController.Modify),
									nameof(ConferenceTrafficController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
								$("#frmDetail").serialize(),
								function(data, textStatus, jqXHR) {
									layer.close(loading);
									if (data.result == "@ConstValues.AjaxFailResult") {
										common.showError(data.message);
									} else {
										common.showSuccess(data.message, true);
										$("#detailWindow").window("close");
										$("#dataGrid").datagrid("reload");
									}
								}
							);
							break;
					}
				}
			});
		}
	}
</script>
}